<template>
  <div>
    <div class="front-header">
      <div class="front-header-left">
        <!--<img src="@/assets/imgs/logo.png" alt="">-->
        <div class="title">爱民宿 B&B</div>
      </div>
      <div class="front-header-center">
        <div class="front-header-nav">
          <el-menu :default-active="$route.path" mode="horizontal" router>
						<el-menu-item index="/front/ho">首页</el-menu-item>
            <el-menu-item index="/front/myOrder">我的订单</el-menu-item>
						<el-menu-item index="/front/myCollect">我的收藏</el-menu-item>

						<el-menu-item index="/front/person">个人信息</el-menu-item>
          </el-menu>
        </div>
      </div>
      <div class="front-header-right">
        <div v-if="!user.username">
          <el-button @click="$router.push('/login')">登录</el-button>
          <el-button @click="$router.push('/register')">注册</el-button>
        </div>
        <div v-else>
         <el-row style="z-index: 999999">
<!--           <el-dropdown trigger="click" style="z-index: 1000">-->
<!--             <div class="front-header-dropdown">-->
<!--               <img :src="visitPath()+user.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" />-->
<!--               <div style="margin-left: 10px">-->
<!--                 <span>{{ user.name }}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>-->
<!--               </div>-->
<!--             </div>-->
<!--             <el-dropdown-menu slot="dropdown">-->
<!--               <el-dropdown-item icon="el-icon-plus" @click="logout">退出</el-dropdown-item>-->
<!--             </el-dropdown-menu>-->
<!--           </el-dropdown>-->
           <div class="front-header-dropdown" style="display: flex;align-items: center">
             <img :src="visitPath()+user.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" />
             <div style="margin:0 10px 0 10px">{{ user.name }}</div>
             <el-button type="danger" @click="logout">退出</el-button>
           </div>
         </el-row>



        </div>
      </div>
    </div>
    <!--主体-->
    <div class="main-body">
      <router-view ref="child" @update:user="updateUser" />
    </div>
  </div>

</template>

<script>

import {visitPath} from "@/Interface/FileApi";

export default {
  name: "FrontLayout",

  data () {
    return {
      top: '',
      notice: [],
      user: JSON.parse(localStorage.getItem("xm-user") || '{}'),
    }
  },

  mounted() {
    this.loadNotice()
  },
  methods: {
    visitPath() {
      return visitPath
    },
    loadNotice() {
      this.$request.get('/notice/selectAll').then(res => {
        this.notice = res.data
        let i = 0
        if (this.notice && this.notice.length) {
          this.top = this.notice[0].content
          setInterval(() => {
            this.top = this.notice[i].content
            i++
            if (i === this.notice.length) {
              i = 0
            }
          }, 2500)
        }
      })
    },
    updateUser() {
      this.user = JSON.parse(localStorage.getItem('xm-user') || '{}')   // 重新获取下用户的最新信息
    },
    // 退出登录
    logout() {
      localStorage.removeItem("xm-user");
      this.$router.push("/login");
    },
  }

}
</script>

<style scoped>
  @import "../assets/css/front.css";
</style>
